/**
 * Created by Jacky
 *
 * brief :
 */


define('ssq/Object', function(require){
    "use strict";

    var SSQ = KG.Class.define('ssq.Object', {
        _init : function(option){
            this.id = option.id;
            this.time = option.time;
            this.hong = option.hong || [];
            this.lan = option.lan;

            this.initVar();
        },

        initVar : function(){
            this.hong = this.hong.sort(function(a, b){
                return a > b;
            });

            this.h1 = parseInt(this.hong[0], 10);
            this.h2 = parseInt(this.hong[1], 10);
            this.h3 = parseInt(this.hong[2], 10);
            this.h4 = parseInt(this.hong[3], 10);
            this.h5 = parseInt(this.hong[4], 10);
            this.h6 = parseInt(this.hong[5], 10);

            this.l = parseInt(this.lan, 10);

            this.opentime = new Date(parseInt(this.time));

            this.max = this.maxHong();

            this.ac = this.getAc();
            this.kuadu = this.getKuadu();
        },

        eachHong : function(callback){
            var hong = [this.h1, this.h2, this.h3, this.h4, this.h5, this.h6];
            KG.each(hong, function(index, num){
                return callback(num);
            });
        },

        /*
        * @brief : 杀红，红6-红1
        * */
        h6_minus_h1 : function(){
            return this.h6 - this.h1;
        },

        /*
        * @breif : 杀红，h5-h4
        *
        * */
        h5_minus_h4 : function(){
            return this.h5 - this.h4;
        },

        /*
        * @brief : 杀红，h5-h2
        * */
        h5_minus_h2 : function(){
            return this.h5 - this.h2;
        },

        maxHong : function(){
            return KG.Number.max(this.h1, this.h2, this.h3, this.h4, this.h5, this.h6);
        },

        /*
        * @breif : 获得AC指，AC应该在 2-10之间，但是统计结果显示大部分在 4-10
        *          其中 8 可能行最大  8>7>6>9>10
        * */
        getAc : function(){
            var map = {};

            function get(x){
                x = x.toString();
                if(!map[x]){
                    map[x] = true;
                }
            }

            get(this.h6-this.h5);
            get(this.h6-this.h4);
            get(this.h6-this.h3);
            get(this.h6-this.h2);
            get(this.h6-this.h1);

            get(this.h5-this.h4);
            get(this.h5-this.h3);
            get(this.h5-this.h2);
            get(this.h5-this.h1);

            get(this.h4-this.h3);
            get(this.h4-this.h2);
            get(this.h4-this.h1);

            get(this.h3-this.h2);
            get(this.h3-this.h1);

            get(this.h2-this.h1);

            var len = KG.Map.size(map);

            return len - (6 - 1);
        },

        /*
        * @brief : 计算跨度
        * */
        getKuadu : function(){
            return this.h6 - this.h1;
        },

        /*
        * @breif : 计算小中大的比重，以11为界限划分
        * @return : [xiao, zhong, da]
        * */
        getXiaoZhongDa : function(){
            var a = 0, b = 0, c = 0;
            this.eachHong(function(num){
                if(num < 12){
                    a++;
                }
                else if(num > 22){
                    c++;
                }
                else{
                    b++;
                }
            });

            return [a, b, c];
        }


      });


    return SSQ;
});